package com.knowledge.action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.opensymphony.xwork2.ActionSupport;
import com.knowledge.DAO.*;;

public class DeleteAction extends ActionSupport {
	private int knowledgeId;


	public int getKnowledgeId() {
		return knowledgeId;
	}


	public void setKnowledgeId(int knowledgeId) {
		this.knowledgeId = knowledgeId;
	}


	@Override
	public String execute() throws Exception {
		
		Connection con=DBpool.getConnection();		
		
		PreparedStatement prepstmt1=null;
		PreparedStatement prepstmt2=null;
		try {
			
			String sql1="delete from user_knowledge_own where knowledgeid=?" ;
			String sql2="delete from knowledge where id=? ";
			
			prepstmt1=con.prepareStatement(sql1);
			prepstmt1.setInt(1, knowledgeId);
			prepstmt1.executeUpdate();
			
			prepstmt2=con.prepareStatement(sql2);
			prepstmt2.setInt(1, knowledgeId);
			prepstmt2.executeUpdate();
			
			prepstmt1.close();
			prepstmt2.close();
			con.close();
			
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return "success";
		
	}
	
	

}
